package com.dys.controller;

import com.dys.pojo.User;
import com.dys.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @className: com.dys.controller.UserController
 * @description: com.dys.controller
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/10/27 11:23
 */
@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = {"/login.do"}, method = RequestMethod.POST)
    public String login(String username, String password) {
        String view = "";
        User user = userService.findUser(username, password);
        if (user != null) {
            System.out.println("登录成功......");
            view = "redirect:/success.jsp";
        } else {
            view = "redirect:/fail.jsp";
        }
        return view;
    }

    @ResponseBody
    @RequestMapping(value = {"/findAllUsers.do"})
    public List<User> findAllUsers() {
        System.out.println("获取所有账号信息成功......");
        return userService.findAllUsers();
    }
}
